package com.dt.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.async.DeferredResult;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger配置
 *
 * @author 大头
 * @since 2019-05-16
 */
@Configuration
@EnableSwagger2
@Slf4j
public class Swagger2Config {

    /**
     * api
     *
     * @return Docket
     */
    @Bean
    public Docket ProductApi() {
        log.info("==================== 开启Swagger2配置 ====================");
        log.info("==================== 访问网址：IP:Port/doc.html ====================");
        log.info("==================== 访问网址：IP:Port/swagger-ui.html ====================");
        return new Docket(DocumentationType.SWAGGER_2)
                .genericModelSubstitutes(DeferredResult.class)
                .useDefaultResponseMessages(false)
                .forCodeGeneration(false)
                .pathMapping("/")
                .select()
                .build()
                .apiInfo(productApiInfo());
    }

    /**
     * apiInfo
     *
     * @return ApiInfo
     */
    private ApiInfo productApiInfo() {
        return new ApiInfoBuilder()
                .title("springboot利用swagger2构建api文档")
                .description("这是一个swagger2的描述")
                .termsOfServiceUrl("该文档的url")
                .version("版本号")
                .build();
    }
}